<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

<%--
  Created by Petro 21.01.13 1:06
--%>
<form:form method="POST" action="/users?form=profile" modelAttribute="profile" enctype="multipart/form-data">
    <tiles:insertDefinition name="editForm">
        <tiles:putAttribute name="title"><spring:message code="label.profile.edit.title"/></tiles:putAttribute>
        <tiles:putAttribute name="data">
            <table>
                <tbody>
                    <tr>
                        <td>
                            <c:choose>
                                <c:when test="${not empty profile.user.photo}">
                                    <img src="${pageContext.request.contextPath}/images?id=${profile.user.id}" alt="${message.sender.displayedFullName}">
                                </c:when>
                                <c:otherwise>
                                    <img src="/resources/image/default_avatar_200.png" alt="${message.sender.displayedFullName}">
                                </c:otherwise>
                            </c:choose>
                        </td>
                        <td id="profileViewRows">
                            <div class="formRow">
                                <div class="labelDiv">
                                    <label class="label"><spring:message code="label.profile.photo"/>:</label>
                                </div>
                                <div class="valueDiv">
                                    <input type="file" name="image"/> <%--name не должен совпадать с именами полей в modelAttribute--%>
                                </div>
                            </div>
                            <tiles:insertDefinition name="inputRow">
                                <tiles:putAttribute name="path" value="contact"/>
                                <tiles:putAttribute name="label"><spring:message code="label.profile.contacts"/></tiles:putAttribute>
                                <tiles:putAttribute name="data">
                                    <form:input path="contact"/>
                                </tiles:putAttribute>
                            </tiles:insertDefinition>
                            <tiles:insertDefinition name="inputRow">
                                <tiles:putAttribute name="path" value="personal"/>
                                <tiles:putAttribute name="label"><spring:message code="label.profile.personal"/></tiles:putAttribute>
                                <tiles:putAttribute name="data">
                                    <form:input path="personal"/>
                                </tiles:putAttribute>
                            </tiles:insertDefinition>
                            <tiles:insertDefinition name="inputRow">
                                <tiles:putAttribute name="path" value="career"/>
                                <tiles:putAttribute name="label"><spring:message code="label.profile.career"/></tiles:putAttribute>
                                <tiles:putAttribute name="data">
                                    <form:input path="career"/>
                                </tiles:putAttribute>
                            </tiles:insertDefinition>
                            <tiles:insertDefinition name="inputRow">
                                <tiles:putAttribute name="path" value="specialization"/>
                                <tiles:putAttribute name="label"><spring:message code="label.profile.specialization"/></tiles:putAttribute>
                                <tiles:putAttribute name="data">
                                    <form:input path="specialization"/>
                                </tiles:putAttribute>
                            </tiles:insertDefinition>
                            <div class="formRow">
                                <button type="submit"><spring:message code="label.button.save"/></button>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </tiles:putAttribute>
    </tiles:insertDefinition>
</form:form>

<form:form method="POST" action="/users?form=name" modelAttribute="nameForm">
    <tiles:insertDefinition name="editForm">
        <tiles:putAttribute name="title"><spring:message code="label.profile.name.edit.title"/></tiles:putAttribute>
        <tiles:putAttribute name="description"><spring:message code="label.profile.edit.description" htmlEscape="false"/></tiles:putAttribute>
        <tiles:putAttribute name="data">
            <c:choose>
                <c:when test="${profile.user.jur}">
                    <tiles:insertDefinition name="inputRow">
                        <tiles:putAttribute name="path" value="name"/>
                        <tiles:putAttribute name="label"><spring:message code="label.profile.name"/></tiles:putAttribute>
                        <tiles:putAttribute name="required" value="true"/>
                        <tiles:putAttribute name="data">
                            <form:input path="name"/>
                        </tiles:putAttribute>
                    </tiles:insertDefinition>
                </c:when>
                <c:otherwise>
                    <tiles:insertDefinition name="inputRow">
                        <tiles:putAttribute name="path" value="surName"/>
                        <tiles:putAttribute name="label"><spring:message code="label.profile.surName"/></tiles:putAttribute>
                        <tiles:putAttribute name="required" value="true"/>
                        <tiles:putAttribute name="data">
                            <form:input path="surName"/>
                        </tiles:putAttribute>
                    </tiles:insertDefinition>
                    <tiles:insertDefinition name="inputRow">
                        <tiles:putAttribute name="path" value="firstName"/>
                        <tiles:putAttribute name="label"><spring:message code="label.profile.firstName"/></tiles:putAttribute>
                        <tiles:putAttribute name="required" value="true"/>
                        <tiles:putAttribute name="data">
                            <form:input path="firstName"/>
                        </tiles:putAttribute>
                    </tiles:insertDefinition>
                    <tiles:insertDefinition name="inputRow">
                        <tiles:putAttribute name="path" value="patrName"/>
                        <tiles:putAttribute name="label"><spring:message code="label.profile.patrName"/></tiles:putAttribute>
                        <tiles:putAttribute name="data">
                            <form:input path="patrName"/>
                        </tiles:putAttribute>
                    </tiles:insertDefinition>
                </c:otherwise>
            </c:choose>
            <div class="formRow">
                <button type="submit"><spring:message code="label.button.save"/></button>
            </div>
        </tiles:putAttribute>
    </tiles:insertDefinition>
</form:form>

<form:form method="POST" action="/users?form=password" modelAttribute="changePassFromProfileForm">
    <tiles:insertDefinition name="editForm">
        <tiles:putAttribute name="title"><spring:message code="label.change.pass.title"/></tiles:putAttribute>
        <tiles:putAttribute name="description"><spring:message code="label.change.pass.description"/></tiles:putAttribute>
        <tiles:putAttribute name="data">
            <tiles:insertDefinition name="inputRow">
                <tiles:putAttribute name="path" value="currentPassword"/>
                <tiles:putAttribute name="label"><spring:message code="label.profile.current.pass"/></tiles:putAttribute>
                <tiles:putAttribute name="data">
                    <form:password path="currentPassword"/>
                </tiles:putAttribute>
            </tiles:insertDefinition>
            <tiles:insertDefinition name="inputRow">
                <tiles:putAttribute name="path" value="passwordForm.newPassword"/>
                <tiles:putAttribute name="label"><spring:message code="label.change.pass.newPassword"/></tiles:putAttribute>
                <tiles:putAttribute name="data">
                    <form:password path="passwordForm.newPassword"/>
                </tiles:putAttribute>
            </tiles:insertDefinition>
            <tiles:insertDefinition name="inputRow">
                <tiles:putAttribute name="path" value="passwordForm.confirmPassword"/>
                <tiles:putAttribute name="label"><spring:message code="label.change.pass.confirmPassword"/></tiles:putAttribute>
                <tiles:putAttribute name="data">
                    <form:password path="passwordForm.confirmPassword"/>
                </tiles:putAttribute>
            </tiles:insertDefinition>
            <div class="formRow">
                <button type="submit"><spring:message code="label.button.save"/></button>
            </div>
        </tiles:putAttribute>
    </tiles:insertDefinition>
</form:form>